﻿Public Class clsGtPgdMesWorkReport
    Public Function getList(startTime As String, endTime As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select a.*,b.oper_type,b.type_value,b.batch_no,c.* from sf.b_gt_pgd_mes_workreport a "
        szSql &= "left join sf.b_gt b on a.b_gt_sys_id = b.sys_id "
        szSql &= "left join sf.b_gt_pgd_mes c on a.b_gt_pgd_mes_sys_id = c.sys_id"
        szSql &= " where 1=1 "
        szSql &= " and b.oper_type = ? "
        If startTime <> "" Then
            szSql &= " and a.update_time >= '" + startTime + "'"
        End If
        If endTime <> "" Then
            szSql &= " and a.update_time <= '" + endTime + "'"
        End If
        Return DBacs.ExecuteSql(szSql, -1, "0")
    End Function

    Public Function getListByGtPgdMesSysId(gtPgdMesSysId As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select sys_id from sf.b_gt_pgd_mes_workreport "
        szSql &= "where 1=1 and b_gt_pgd_mes_sys_id = ?"
        Return DBacs.ExecuteSql(szSql, -1, gtPgdMesSysId)
    End Function

    Public Function getListByGtPgdmesSysId(oper_type As String, gtSysId As String) As DataTable
        Dim szSql As String = ""
        szSql &= " select sys_id from sf.b_gt_pgd_mes_workreport "
        szSql &= "where 1=1 and oper_type = ? and b_gt_sys_id = ?"
        Dim dt As DataTable = DBacs.ExecuteSql(szSql, -1, oper_type, gtSysId)
        If IsNothing(dt) Then
            getListByGtPgdmesSysId = New DataTable
        Else
            getListByGtPgdmesSysId = dt
        End If
    End Function

    Public Function insert(oper_type As String, gtSysId As String, gtPgdMesSysId As String, oper_num As String, oper_user As String) As Integer
        Dim sql As String = ""
        Dim rtn As Integer
        DBacs.BeginTransaction()
        Try
            sql &= "INSERT INTO sf.b_gt_pgd_mes_workreport(oper_type,b_gt_sys_id, b_gt_pgd_mes_sys_id,oper_num, operator, update_time)  "
            sql &= "VALUES ( ?, ?, ?, ?, ?, (SELECT CURRENT_TIMESTAMP(6)))"
            rtn = DBacs.ExecuteUpdateSql(sql, -1， oper_type, gtSysId, gtPgdMesSysId, oper_num, oper_user)
            sql = ""
            sql &= "UPDATE sf.b_gt_pgd_mes SET finish_count = ? WHERE sys_id = ? "
            rtn = DBacs.ExecuteUpdateSql(sql, -1, oper_num, gtPgdMesSysId)
            DBacs.CommitTransaction()
        Catch ex As Exception
            DBacs.RollbackTransaction()
            rtn = -2
        End Try
        Return rtn
    End Function

End Class
